
window.fps = 30
// 临时调试用代码
var paused = false

var enableDebugMode = function(ball,enable,scene) {
    if (!enable) {
        return
    }
    window.addEventListener('keydown', function (event) {
        let k = event.key
        // log('key', event)
        if (k == ' ') {
            paused = !paused
        } else if ('12345'.includes(k)) {
            blocks = scene.loadlevel(Number(k))
        }
    })
    // 控制速度
    document.querySelector('#id-input-speed').addEventListener('input', function (event) {
        var input = event.target
        // log(event, input.value)
        window.fps = Number(input.value)
    })

    // 拖拽小球
    var enableDrag = false
    window.addEventListener('mousedown', function (event) {
        let X = event.offsetX
        let Y = event.offsetY
        // log(typeof ball.image.width)

        if (ball.x <= X && X <= (ball.x + ball.image.width) && ball.y <= Y && Y <= (ball.y + ball.image.width)) {
            enableDrag = true
        }
    })
    window.addEventListener('mousemove', function (event) {
        if (enableDrag) {
            let X = event.offsetX
            let Y = event.offsetY
            ball.x = X
            ball.y = Y
        }
    })
    window.addEventListener('mouseup', function (event) {
        enableDrag = false
    })
}

// 添加自定义事件
var titleMessage = new EventTarget()
titleMessage.addHandler('MESSAGE', function (event) {
    let t = document.getElementsByTagName('title')
    t[0].innerHTML = event.message
    console.log(event.message)
})  
var images = {
    'paddle':'img/paddle.png',
    'ball':'img/ball.png',
    'block':'img/block.png',
}

var __main = function () {
    // log(paddle)
    var game = XsGame.instance(images,function(g) {
        var scene_title = SceneTitle(g)
        g.runWithScene(scene_title)
    })
    // scence.dr
}

__main()